﻿using System;
using System.Collections.Generic;
using System.Linq;
using LayerData;
using LayerData.Hotel;
using LayerEntity.Hotel;

namespace LayerLogic.Hotel
{
    public class LHotel
    {
        #region Variables
        public delegate void AddObject(string msj, EnumOperaciones op, EnumEstadoOperaciones est);
        public event AddObject UpdateList = delegate { };
        readonly IPostgreSqlConnectionInfo connectionInfo;
        readonly DHotel common;
        List<EHotel> listHotel;
        List<EPisos> listPisos;
        List<ETipoHabitacion> listTipoHabitacion;
        #endregion
        #region Constructores
        public LHotel()
        {
            this.InicializaVariables();
            this.connectionInfo = ObjectFactory.CreateConnectionInfo();
            this.common = new DHotel(this.connectionInfo);
        }

        public LHotel(IPostgreSqlConnectionInfo connection)
        {
            this.InicializaVariables();
            this.connectionInfo = connection;
            this.common = new DHotel(connection);
        }

        #endregion
        #region Metodos Privados
        private void InicializaVariables()
        {
            this.listHotel = new List<EHotel>();
            this.listPisos = new List<EPisos>();
            this.listTipoHabitacion = new List<ETipoHabitacion>();
        }

        #endregion
        #region RecordManagerHotel
        public List<EHotel> GetHoteles()
        {
            if (this.listHotel.Count == 0)
            {
                this.listHotel = this.common.GetHoteles();
            }
            return this.listHotel;
        }

        public List<EPisos> GetPisosHotel()
        {
            if (this.listPisos.Count == 0)
            {
                this.listPisos = this.common.GetPisosHotel();
            }
            return this.listPisos;
        }

        public List<ETipoHabitacion> GetTiposHabitaciones()
        {
            if (this.listTipoHabitacion.Count == 0)
            {
                this.listTipoHabitacion = this.common.GetTiposHabitaciones();
            }
            return this.listTipoHabitacion;
        }
        #endregion
    }
}